import lazyLoad from "./lazyLoad.js";
import Render from "./render.js";
export default class index {
    usermsg;
    id
    ret1
    constructor() {
        //用户名
        this.usermsg = JSON.parse(sessionStorage.getItem("usermsg"));
        this.username = document.getElementById("username");
        if (this.usermsg) this.writeUserMsg();
        this.myCar = document.getElementById("myCar")
        this.lis = document.querySelectorAll("lis")
        this.selectProList()
        this.bindEvent()
        new lazyLoad("banner img")
    }
    writeUserMsg() {
        this.username.innerHTML = this.usermsg.username
        this.username.className = "login"
    }
    bindEvent() {
        this.myCar.addEventListener("click", e => this.carclickHandler(e));
    }

    carclickHandler(e) {
        if (this.usermsg) {
            this.goCar(this.id)
            this.id = this.usermsg.username
        }
        else {
            alert("未登录")
            location.href = "./signIn.html";
        }
    }
    goCar(id) {
        location.href = "./car.html#id=" + id;
    }
    async selectProList() {
        fetch("http://localhost:4022/prolist").then(res => res.json())
            .then(res => {
                this.render(res)
            })

    }
    render() {
        this.ret1 = new Render("ziyiZiYiMall");
        this.ret1.pfetch(0, 3);
        this.ret1 = new Render("ziyinv");
        this.ret1.pfetch(4, 11);
        this.ret1 = new Render("ziyinan");
        this.ret1.pfetch(12, 19);
        this.ret1 = new Render("ziyiparents");
        this.ret1.pfetch(20, 27);
        this.ret1 = new Render("ziyiZQMY");
        this.ret1.pfetch(28, 35);
        this.ret1 = new Render("ziyiZB");
     
    }




}



new index();




// var arr = res.filter((item, index) => {
//     if (index < 4) {
//         return item
//     }
// })
// console.log(arr)
// var str = arr.map(item => {

//     return 
//     `<li data-id="${item.proID}">
// 				<a href="../details.html#id=${item.proID}" data-id="${item.proID}">
//                 <img src="${item.src}" data-id="${item.proID}">
// 					<h3 class="layui-elip" data-id="${item.proID}">
// 						<img src="https://www.ziyimall.com/file_img/activity/twelve/icon-12.png?n=3" data-id="${item.proID}" />
// 						<span class="layui-elip" id="title" data-id="${item.proID}">${item.title}</span>
// 					</h3>
// 					<div class="other">
// 						<p>
// 							<strong><em>￥</em>${item.price}</strong>
// 							<span style="margin: 0;">￥${item.no_price}</span>
// 						</p>
// 						<button>${item.buy}</button>
// 					</div>
// 				</a>
// 			</li>`
// }).join("");
// this.ziyiZiYiMall.innerHTML = str